package com.youfang.sixthmedia.ui.detail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;

import com.gzit.activity.GzitTabHostActivity;
import com.gzit.common.async.AsynCallback;
import com.gzit.utils.AndroidUtils;
import com.youfang.sixthmedia.R;
import com.youfang.sixthmedia.common.YoufangContext;
import com.youfang.sixthmedia.message.GethousedetailRequest;
import com.youfang.sixthmedia.message.GethousedetailResponse;
import com.youfang.sixthmedia.net.Net;
import com.youfang.sixthmedia.net.Response;

public class TabDetailBuildingActivity extends GzitTabHostActivity {

	private String houseId;

	private void setupTestStub() {
		houseId = "5016";

	}

	@Override
	protected Class<Activity>[] getHostActivitys() {
		return new Class[] { DetailBuildingActivity.class,
				DetailConsultantActivity.class, DetailCommentActivity.class,
				DetailBuildingBuddyActivity.class };
	}

	@Override
	protected int[] getRadioBtnIds() {
		return new int[] { R.id.mainRB, R.id.consultantRB, R.id.commentRB,
				R.id.nearbyRB };
	}

	@Override
	public Intent onCreateIntent(Class<Activity> activity) {
		Intent intent = new Intent();
		intent.setClass(this, activity);
		intent.putExtra("detail", YoufangContext.getCurrentBuilding());
		return intent;
	}

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.tab_building_activity);

		Intent intent = this.getIntent();
		houseId = intent.getStringExtra("id");

		// test...
		// setupTestStub();
		this.remoteLoadBuildingDetail(new AsynCallback<Response>() {

			@Override
			public void callback(Response r) {
				setupIntents();
			}

		});

	}

	public void init() {

	}

	public void setupIntents() {
		// TabDetailBuildingActivity.detail = detail;
		super.init();
		((RadioButton) this.findViewById(R.id.mainRB)).setChecked(true);
	}

	public void remoteLoadBuildingDetail(final AsynCallback<Response> callback) {

		GethousedetailRequest req = new GethousedetailRequest();
		req.setId(this.houseId);

		Net.doHttpRemote(this, req, new GethousedetailResponse(),
				new AsynCallback<Response>() {

					@Override
					public void callback(Response r) {

						if (!r.isOk()) {
							AndroidUtils.toastShort("更新楼盘详情失败");
							return;
						}

						GethousedetailResponse resp = (GethousedetailResponse) r;
						YoufangContext.setCurrentBuilding(resp.getDetail());
						callback.callback(resp);

					}

				});

	}

}
